package com.panshi.controller;

import com.panshi.IZxArticleApi;
import com.panshi.IZxUncheckApi;
import com.panshi.domain.ZxArticle;
import com.panshi.domain.ZxUncheck;
import com.panshi.domain.vo.PageBean;
import com.panshi.domain.vo.QueryVO;
import com.panshi.domain.vo.SearchParams;
import com.panshi.domain.vo.ZxResult;
import com.panshi.vo.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/zx")
public class ZxController {


    @Autowired
    private IZxArticleApi zxArticleApi;

    @Autowired
    private IZxUncheckApi zxUncheckApi;


    //分页查询
    @RequiresPermissions("zx:list:*")
    @PostMapping(value = "/pageZxList",consumes = "application/json")
    public Map<String,Object> pageZxList(@RequestBody QueryVO queryVO){
        R r = zxArticleApi.pageZxList(queryVO);
        Map<String ,Object> map = new HashMap<>();
        map.put("data",r.getData().get("data"));
        map.put("count",r.getData().get("count"));
        map.put("code",r.getCode());
        return map;
    }

    /*@RequiresPermissions("zx:add:*")
    @PostMapping
    public ZxResult addZx(@RequestBody ZxUncheck zxUncheck){
        return zxArticleApi.addZx(zxUncheck);
    }*/


    //上下架
    @RequiresPermissions("zx:edit:*")
    @PutMapping
    public R editState(@RequestBody ZxArticle zxArticle){
        R r = zxArticleApi.updataStatus(zxArticle);
        System.out.println(r);
        return r;
    }


    //删除
    @RequiresPermissions("zx:del:*")
    @DeleteMapping("/{id}")
    public ZxResult delZx(@PathVariable("id")Integer id){
        return zxArticleApi.userDelete(id);
    }

    //查询资讯类型
    @GetMapping("/type")
    public ZxResult getZxType(){
        return zxArticleApi.queryType();
    }

    //查询资讯详情
    @GetMapping("/{id}")
    public R getZxInfo(@PathVariable("id")Integer id){
        return zxArticleApi.adminZxBayId(id);
    }




    //===========================uncheck=========================


    //分页查询未审资讯
    @GetMapping("/un/pageZxUncheckList")
    public Map<String,Object> pageZxUncheckList(Integer page ,Integer limit){
        PageBean pageBean = new PageBean();
        pageBean.setPageSize(limit);
        pageBean.setCurrentPage(page);
        R r = zxUncheckApi.getUncheckAll(pageBean);
        Map<String ,Object> map = new HashMap<>();
        map.put("data",r.getData().get("data"));
        map.put("count",r.getData().get("count"));
        map.put("code",r.getCode());
        return map;
    }


    @PostMapping("/un")
    public ZxResult zxAdd(@RequestBody ZxUncheck zxUncheck){
        return zxUncheckApi.addZxUncheck(zxUncheck);
    }

    //审核资讯
    @PutMapping("/un")
    public R zxCheck(@RequestBody ZxUncheck zxUncheck){
        return zxUncheckApi.uncheckUp(zxUncheck);
    }



    //删除资讯
    @DeleteMapping("/un/{id}")
    public R zxDelete(@PathVariable("id") Integer id){
        return zxUncheckApi.deleteUncheck(id);
    }


    //查询资讯未审详情
    @GetMapping("/un/{id}")
    public R zxGetInfo(@PathVariable("id") Integer id){
        return zxUncheckApi.getUncheckZxBayId(id);
    }



}
